<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Catch</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<link href="../static/theme.css" rel="stylesheet" type="text/css" />
<script src="../static/content.js" type="text/javascript"></script>
</head>
<body>

<h1>Catch <span class="ver">[v1.1.04+]</span></h1>

<p>Specifies the code to execute if an exception is raised during execution of a <a href="Try.htm">try</a> statement.</p>

<pre class="Syntax" style="line-height: 120%">Catch [, OutputVar]
    <i>Statement</i></pre>
<pre class="Syntax" style="line-height: 100%">Catch [, OutputVar]
{
    <i>Statements</i>
}</pre>
<h3>Parameters</h3>
<dl>

  <dt>OutputVar</dt>
  <dd><p><em>(Optional)</em> The name of the variable in which to store the value of the exception.</p></dd>

  <dt><i>Statement(s)</i></dt>
  <dd><p>The commands or expressions to execute if an exception is raised.</p></dd>

</dl>

<h3>Remarks</h3>
<p>Every use of <em>catch</em> must belong to (be associated with) a <a href="Try.htm">try</a> statement above it. A <em>catch</em> always belongs to the nearest unclaimed <em>try</em> statement above it unless a <a href="Block.htm">block</a> is used to change that behavior.</p>
<p>The <a href="Block.htm#otb">One True Brace (OTB) style</a> may optionally be used. For example:</p>
<pre>try <strong>{</strong>
    ...
<strong>}</strong> catch e <strong>{</strong>
    ...
<strong>}</strong></pre>

<h3 id="RuntimeErrors">Runtime Errors</h3>
<p>A <em>try-catch</em> statement can also be used to handle runtime errors. There are two kinds of runtime errors: those which normally set <a href="../misc/ErrorLevel.htm">ErrorLevel</a>, and those which normally cause the current thread to exit after displaying an error message. Loadtime errors cannot be handled, since they occur before the <em>try</em> statement is executed. For backward-compatibility (and in some cases convenience), runtime errors only throw exceptions while a <em>try</em> block is executing. Most commands support the use of <em>try-catch</em>; however, <a href="../misc/ErrorLevel.htm">ErrorLevel</a> is still set to 0 if the command succeeds.</p>
<p>The value that is stored in <em>OutputVar</em> (if present) is an <a href="Throw.htm#Exception">exception object</a>.</p>

<h3>Related</h3>
<p><a href="Try.htm">Try</a>, <a href="Throw.htm">Throw</a>, <a href="Finally.htm">Finally</a>, <a href="Block.htm">Blocks</a></p>
<h3>Examples</h3>
<p>See <a href="Try.htm#Examples">Try</a>.</p>

</body>
</html>
